from django.views.generic.list_detail import object_list
from agro.models import Entry

def tumble_archive(request, username=None, excluded_models=None, template_name='agro/tumble_archive.html'):
	if username != None:
		qs = Entry.objects.filter(owner_user=username)
	else:
		qs = Entry.objects.all()
	if excluded_models != None:
		for excluded_model in excluded_models:
			qs = qs.exclude(source_type=excluded_model)
	qs.order_by('-timestamp')
	return object_list(request,
		queryset=qs,
		template_name=template_name)
	
def tumble_by_model(request, model, username=None, template_name='agro/tumble_archive.html'):
	qs = Entry.objects.filter(source_type=model)
	if username != None:
		qs = qs.filter(owner_user=username)
	qs.order_by('-timestamp')
	return object_list(request,
		queryset=qs,
		template_name=template_name)